package com.ruoyi.project.ypgl.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.ypgl.domain.YpglSccj;
import com.ruoyi.project.ypgl.domain.YpglYpxx;
import com.ruoyi.project.ypgl.service.IYpglYpxxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ypgl/ypxx")
public class YpglYpxxController extends BaseController {

    @Autowired
    private IYpglYpxxService ypglYpxxService;


    @PreAuthorize("@ss.hasPermi('ypgl:ypxx:list')")
    @GetMapping("/list")
    public TableDataInfo list(YpglYpxx ypxx){
        startPage();
        List<YpglYpxx> list = ypglYpxxService.selectYpxxList(ypxx);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('ypgl:ypxx:add')")
    @Log(title = "管理药品信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody YpglYpxx ypxx)
    {

        ypxx.setCreateBy(SecurityUtils.getUsername());
        return toAjax(ypglYpxxService.insetYpxx(ypxx));
    }


    @PreAuthorize("@ss.hasPermi('ypgl:ypxx:query')")
    @GetMapping(value = "/{ypxxId}")
    public AjaxResult getInfo(@PathVariable Long ypxxId)
    {
        return AjaxResult.success(ypglYpxxService.selectYpxxById(ypxxId));
    }


    @PreAuthorize("@ss.hasPermi('ypgl:ypxx:edit')")
    @Log(title = "药品信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody YpglYpxx ypxx)
    {

        ypxx.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(ypglYpxxService.updateYpxx(ypxx));
    }

    @PreAuthorize("@ss.hasPermi('ypgl:ypxx:remove')")
    @Log(title = "药品信息管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ypxxIds}")
    public AjaxResult remove(@PathVariable Long[] ypxxIds)
    {
        return toAjax(ypglYpxxService.deleteYpxxByIds(ypxxIds));
    }



}
